package cn.fruitmarket.shopcar;
import cn.fruitmarket.sellstrategy.IStrategy;
import lombok.Data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
public class ShoppingCar {

    private List<CarItem> items;
    private List<IStrategy> carStrategies;
    private double amount;
    private Date createDate;

    public ShoppingCar() {
        items = new ArrayList<CarItem>();
        carStrategies = new ArrayList<IStrategy>();
        amount = 0;
        createDate = new Date();
    }
    public void addItem(CarItem item) {
        this.items.add(item);
    }
    public void addStragegys(IStrategy strategy){
        this.carStrategies.add(strategy);
    }
    public void accounting(){
        double totalMoney = 0;
        for(CarItem item : items) {
            item.computeAmount(createDate);
            totalMoney+=item.getAmount();
        }
        //可以考虑策略带优先级字段。
        for(IStrategy strategy : carStrategies) {
            totalMoney = strategy.realPrice(createDate,totalMoney);
        }
        this.amount = totalMoney;

    }

}
